import schema from 'async-validator';
export function isMobile (mobile) {
  return /^1[3-9]\d{9}$/.test(mobile)
}

var descriptor = {
  name: {
    type: "string",
    required: true,
    validator: (rule, value) => value === 'muji',
  },
  age: {
    type: "number",
    asyncValidator: (rule, value) => {
        return new Promise((resolve, reject) => {
          if (value < 18) {
            reject("too young");  // reject with error message
          } else {
            resolve();
          }
        });
      }
  }
};


export var validator = new schema(descriptor);


var descriptor = {
  value: {
    type: "string",
    required: true,
    validator: (rule, value) => isMobile(value),
  },
};


export var phoneValidator = new schema(descriptor);